﻿




using System.Web.Mvc;
using Hotpot.Results;
using Hotpot.ViewModels;

namespace Hotpot.Filters
{
    public class ErrorExceptionFilter : IExceptionFilter
    {
        #region IExceptionFilter Members

        public void OnException(ExceptionContext filterContext)
        {
            HotpotViewModel model = filterContext.Controller.ViewData.Model as HotpotViewModel;

            filterContext.Controller.ViewData.Model = new ExceptionHotpotViewModel(model, filterContext.Exception);

#if DEBUG
            filterContext.HttpContext.AddError(filterContext.Exception);
#endif
            filterContext.ExceptionHandled = true;

            filterContext.Result = new ErrorResult();
        }

        #endregion
    }
}
